layui.define(['jquery','configureCom','configure','sessionFun', 'matchDict'], function (exports) {
    var $ = layui.jquery;

    var textStyle = {
        fontWeight: 'bold', // normal  bold
        color: '#02e4ff'
    };

    var lineStyle = {
        color: '#ffffff'
    }


    var echartsCom = {
        newbing:function(toolTitle, echartData){
            $.each(echartData,function(i,item){
               item.value = parseInt(item.value);
            });
            return new Promise(function(res, err){
                var option = {
                    title: {
                        text: '南丁格尔玫瑰图',
                        subtext: '纯属虚构',
                        left: 'center'
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        left: 'center',
                        top: 'bottom',
                        data: ['rose1', 'rose2', 'rose3', 'rose4', 'rose5', 'rose6', 'rose7', 'rose8']
                    },
                    series: [
                        {
                            name: '半径模式',
                            type: 'pie',
                            radius: [20, 110],
                            center: ['25%', '50%'],
                            roseType: 'radius',
                            label: {
                                show: false
                            },
                            data: echartData
                        }
                    ]
                };
                return option;

            })
        },
        /*
        * 饼状图
        * toolTitle:滑到图形上后弹层的title
        * echartData:接口数据
        * legendData : legend
        * legendTop
        * */
        bing:function( toolTitle, echartData, legendData, legendTop){
            return new Promise(function(res, err){
                var option = {
                    title: {
                        text: toolTitle,
                        left: 'center',
                        textStyle: textStyle
                    },
                    tooltip: {
                        trigger: 'item',
                        formatter: '{a} <br/>{b} : {c} ({d}%)'
                    },
                    legend: {
                        show: (legendData == undefined) ? false : true,
                        orient: 'horizontal',
                        right: 10,
                        top:legendTop == undefined ? 10 : legendTop,
                        data: legendData,
                        textStyle:{
                            color:'#fff',
                        }
                    },
                    series: [
                        {
                            name: toolTitle,
                            type: 'pie',
                            radius: '55%',
                            center: ['50%', '60%'],
                            // roseType: 'radius',//是否展示成南丁格尔图，通过半径区分数据大小
                            data: echartData,
                            labelLine: {
                                normal: {
                                    show: true
                                }
                            },
                            label: {
                                normal: {
                                    show: true
                                },
                                emphasis: {
                                    show: true,
                                }
                            },
                            itemStyle: {
                                emphasis: {
                                    shadowBlur: 10,
                                    shadowOffsetX: 0,
                                    shadowColor: 'rgba(0, 0, 0, 0.5)'
                                },
                                normal: {
                                    color:function(params) {
                                        //自定义颜色
                                        var colorList = [
                                            '#00cccc', '#00cc00', '#cccc00', '#aa8C00',
                                            '#ccc000', '#FE8463', '#fef76e','#2dedfe',
                                            '#fe2635','#2a36fe','#efeefe','#fe61d8'
                                        ];
                                        return colorList[params.dataIndex]
                                    }
                                }
                            }

                        }
                    ]
                };
                res(option);
            });
        },
        /*
        * 折线图
        * titleName： 标题
        * xdata: x轴数据
        * series： 数据
        * */
        xian:function(titleName,xdata, series){
            return new Promise(function(res,err){
                var option = {
                    tooltip: {
                        trigger: 'axis',
                        //指示器
                        axisPointer: {
                            type: 'line',
                            lineStyle: lineStyle
                        }
                    },
                    title: {
                        text: titleName,
                        left: 'center',
                        textStyle: textStyle
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        top:'3%',
                        containLabel: true
                    },
                    xAxis: {
                        type: 'category',
                        boundaryGap: false,
                        axisLine:{
                            lineStyle:lineStyle
                        },
                        data: xdata
                    },
                    yAxis: {
                        type: 'value',
                        axisLine:{
                            lineStyle:lineStyle
                        }
                    },
                    series: series,
                };
                res(option);
            });
        },
        /*
        * 柱状图
        *titleName:标题
        * xArr: x轴数据
        *  seriesName:   系列名称
        * echartData ： y轴数据
        * xrotate: x轴是否倾斜数据
        * */
        zhu:function(titleName, xArr, seriesName, echartData, xrotate){
            return new Promise(function(res, err){
                var option = {
                    color: ['#3398DB'],
                    // color:new echarts.graphic.LinearGradient(
                    //     1, 0, 0, 1,
                    //     [
                    //         {offset: 0, color: '#00FF00'},
                    //         {offset: 0.5, color: '#3A8EE6'},
                    //         {offset: 0.8, color: '#FAB6B6'},
                    //         {offset: 1, color: '#ddd'}
                    //     ]
                    // ),
                    title: {
                        text: titleName,
                        left: 'center',
                        textStyle: textStyle
                    },
                    tooltip: {
                        trigger: 'axis',
                        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                        }
                    },
                    grid: {
                        left: '3%',
                        right: '4%',
                        bottom: '3%',
                        containLabel: true
                    },
                    xAxis: [
                        {
                            type: 'category',
                            data: xArr,
                            axisTick: {
                                alignWithLabel: true
                            },
                            axisLine:{
                                lineStyle:lineStyle
                            },
                            axisLabel: {
                                interval:0, //坐标刻度之间的显示间隔，默认就可以了（默认是不重叠）
                                rotate: (xrotate ? 38 : 0)   //调整数值改变倾斜的幅度（范围-90到90）
                            }
                        }
                    ],
                    yAxis: [
                        {
                            type: 'value',
                            axisLine:{
                                lineStyle:lineStyle
                            }
                        }
                    ],
                    series: [
                        {
                            name: seriesName,
                            type: 'bar',
                            barWidth: '60%',
                            data: echartData
                        }
                    ]
                };
                res(option);
            });
        },
    };
    exports('echartsCom', echartsCom);
});